package com.app.Activity;

import java.io.File;
import java.util.ArrayList;

import com.app.Controller.NetworkController;
import com.app.Controller.ReadWriteFileController;
import com.app.DTO.AccountDTO;
import com.app.DTO.RoleDTO;

import ReadWriteXML.CMember;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import app.com.ModuleRole.R;

public class frmTaoNhom extends Activity {
	public static String CODE_GROUP_NAME="CODE_GROUP_NAME";
	int port=5033;
	Button btnTaoNhom;
	Button btnCaiDatVaiTro;
	EditText txtTenNhom;
	EditText txtSoLuongThanhVien;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		int port=8800;
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_tao_nhom);
		btnTaoNhom=(Button)findViewById(R.id.btnTaoNhom);
		btnCaiDatVaiTro=(Button)findViewById(R.id.btnCaiDatVaiTro);
		txtTenNhom=(EditText)findViewById(R.id.txtTenNhom);
		txtSoLuongThanhVien=(EditText)findViewById(R.id.txtSoLuongThanhVien);
		
		btnTaoNhom.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {				
				 createMemberFile();
				Intent i=new Intent(getBaseContext(),frmNhomChoActivity.class);
				i.putExtra(CODE_GROUP_NAME, txtTenNhom.getText().toString());
				startActivity(i);				
			}
		});
		
		btnCaiDatVaiTro.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {		

				Intent i=new Intent(getBaseContext(),frmQuanLyRoleActivity.class);
				startActivity(i);
			}
		});
	}
	private void createMemberFile(){
		CMember member=new CMember();
		member.set_fullName(NetworkController._peer.account.get_Username());
		member.set_ip(NetworkController._peer.getAddressPeer());
		member.set_userName(NetworkController._peer.account.get_Username());
		File f=new File(ReadWriteFileController.MEMBER_PATH);
		f.delete();
		ReadWriteFileController.insertMember(ReadWriteFileController.MEMBER_PATH, member);
	}
	@Override
	public void onStart(){
		super.onStart();
//		AccountDTO account=new AccountDTO();
//		ArrayList<RoleDTO> roleList=ReadWriteFileController.readRole(ReadWriteFileController.ROLE_DEFAULT_PATH);
//		for(RoleDTO role:roleList){
//			account.addRole(role);
//		}
//		
//		NetworkController.init("MES", port, account);
	}

}
